# _*_coding:utf-8_*_
# 词性标注
import jieba.posseg
import jieba.analyse
from sanic import Sanic
from sanic.response import json as sanic_json

jieba.enable_paddle()  # 开启paddle模式

app = Sanic()


@app.route("/tagging", methods=["POST"])
async def tagging(request):
    json = request.json
    print(json)
    sentence = json["text"]
    words = jieba.posseg.cut(sentence, use_paddle=True)
    result = ""
    for item in words:
        result = result + item.word + "-->" + item.flag + " "
    print(result)
    result = {"tagging": result}
    return sanic_json(result)


if __name__ == '__main__':
    app.run(host="localhost", port=8080)
